package com.wn.consumer.demo06;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.rabbitmq.client.Channel;
import com.wn.bean.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;


/**
 * @author yellow Docter
 * @date 2022 -11-03
 * @desc
 */
@Component
@Slf4j
public class BeanConsuerm {

    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(name = "bean_queue"
                    ),
                    exchange = @Exchange(name = "exchange_bean",type = ExchangeTypes.DIRECT),
                    key = "msg.bean"
            )
    )
    public void handlerMsg(@Payload User user){
//    public void handlerMsg(String str) throws JsonProcessingException {
//
//        ObjectMapper objectMapper = new ObjectMapper();
//        User user = objectMapper.readValue(str, User.class);

        log.info("拿到了发送的消息bean:{}",user);

    }

}